/**********************************************************************************
// Game Header File
//
// Creation:	24 Ago 2007
// Updated:		30 Set 2009
// Compiler:	Visual Studio 2008
//
// Notes:		The Game class has all the pixel plotting functions that access  
//              the video card memory directly, and all the blitting functions 
//              that draw using the graphics hardware.
//
**********************************************************************************/

#ifndef _ANABELE_GAME_H_
#define _ANABELE_GAME_H_

/**********************************************************************************/


// The project that builds the DLL should define the constant ANABELE_EXPORTS
// in the command line of the compiler. In this way all classes will be marked
// with __declspec( dllexport ). The constant should not be defined by the 
// applications' project using the DLL. In the applications' project all 
// classes must be marked with _declspec( dllimport ).

#ifdef ANABELE_EXPORTS
#define DLL __declspec( dllexport ) 
#else
#define DLL __declspec( dllimport )
#endif 

/**********************************************************************************/

// Includes
#include "D3DGame.h"   // Direct3D class definition
#include "Bitmap.h"			// Bitmap class definition
#include "Geometry.h"		// Geometry class definition

/**********************************************************************************/

class DLL Game : public D3DGame
{
private:
	RECT clientWindow;													// clipping rectangle

	// private methods
	void Plot(int x, int y, int flag, DWORD color);						// plot pixels for DrawFastLine method
	void DrawFastPixel(int x, int y, DWORD color);						// plot pixels (no clipping)
	void DrawFastLine(int a1, int b1, int a2, int b2, DWORD color);		// draw a line (no clipping)
	int  ClipLine(int &x1, int &y1, int &x2, int &y2);					// clip a line to the window rectangle
	void DrawFastImage(const Bitmap &bmp,
		               int imgX1, int imgY1,				
		               int imgX2, int imgY2, 
					   int xpos, int ypos);								// draw bitmap (no clipping)

public:
	Game();																// Game constructor
	~Game();															// Game destructor

	// Overwrite windowsGame member functions 
	// to properly set the clientWindow clipper 
	void SetWindowWidth(int width);										// set window width
	void SetWindowHeight(int height);									// set window height


	// All the public methods use the clipper: everything is clipped 
	// to the coordinates defined by the private member clientWindow

	void Draw(const Point& point, const Color& col);					// draw a pixel
	void Draw(const Line& line, const Color& col);						// draw a line 
	void Draw(const Rect& rect, const Color& col);						// draw a rectangle
	void Draw(const Circle& circle, const Color& col);					// draw a circle
	void Draw(const Poly& poly, const Color& col);						// draw a polygon 
	void Draw(const Bitmap &bmp, int xpos, int ypos);					// draw image pixel by pixel
};

/**********************************************************************************/

// InLine Member Functions

// plot pixels for DrawFastLine method
inline void Game::Plot(int x, int y, int flag, DWORD color)
{ flag ? DrawFastPixel(y,x,color) : DrawFastPixel(x,y,color); }

// plot pixels (no clipping)
inline void Game::DrawFastPixel(int x, int y, DWORD color)						
{ videoMemory[x + y * videoMemoryPitch] = color; }

/**********************************************************************************/

#endif